<?php
namespace admin\models;

use common\models\User;
use common\models\SearchInterface;
use common\models\SearchTrait;
use Yii;

class UserSearch extends User implements SearchInterface
{
    use SearchTrait;

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['gid', 'role_id'], 'integer'],
            [['user_name', 'user_id'], 'trim'],
        ];
    }

    public function prepareQuery($query)
    {
        return $query->andFilterWhere(['gid' => $this->gid, 'role_id' => $this->role_id, 'user_id' => $this->user_id])
            ->andFilterWhere(['like', 'user_name', $this->user_name])
            ->orderBy(['created_at' => SORT_DESC]);
    }
}
